package generadorDescriptores.dom;

import java.util.Iterator;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

import com.google.gwt.dom.client.NodeList;

public class DimensionDom {
	private Element elementDimension;
	private Document document; 
	
	public DimensionDom(Document doc){
		this.document = doc;
		this.elementDimension = doc.createElement("dimension");
	}
	
	public Element getElement(){
		return elementDimension;
	}
	
	/**
	 * This method will be invoked from the UI.
	 * @param name
	 */	
	public void setAttributes(String name){
		elementDimension.setAttribute("name", name);
	}
	
	public void addProperty(DimensionPropertyDom property){
		elementDimension.appendChild(property.getElement());
	}
	
	public void removeProperty(String propertyName){
		org.w3c.dom.NodeList properties = elementDimension.getElementsByTagName("property");
		for(int i=0; i<properties.getLength(); i++){
			NamedNodeMap attributes= properties.item(i).getAttributes();
			if (attributes.getNamedItem("name").equals(propertyName)){
				this.elementDimension.removeChild(properties.item(i));
			}
		}
	}
		
	
	
	
}
